package com.time.company.db.dao.impl;


import com.time.company.db.dao.BaseDao;
import com.time.company.db.model.PicModel;

import org.litepal.crud.DataSupport;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Bing on 2017/7/27.
 * E-mail is tx16bing@163.com
 */

public class PicDdao extends BaseDao<PicModel> {

    @Override
    public boolean save(PicModel bean) {
        delete(bean);
        return bean.save();
    }

    @Override
    public List<PicModel> find() {
        List<PicModel> all = DataSupport.findAll(PicModel.class);
        if (all == null){
            all = new ArrayList<>();
        }
        return all;
    }

    public List<PicModel> find(String topicId) {
        List<PicModel> all = DataSupport.where("topicid=?", topicId).find(PicModel.class);
        if (all == null){
            all = new ArrayList<>();
        }
        return all;
    }

    @Override
    public int delete(PicModel bean) {
        // 删除缓存数据
        return DataSupport.deleteAll(PicModel.class, "topicid=? and picid=?", bean.getTopicId(), bean.getPicId());
    }

}
